package com.star.warmwinter.module.user.viewCtrl;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;

import com.star.tool.util.RegexUtils;
import com.star.warmwinter.R;
import com.star.warmwinter.module.user.ui.CommonLoginPwdActivity;
import com.star.warmwinter.module.user.ui.CommonLoginTelActivity;
import com.star.warmwinter.widget.ThemeToast;

import static com.star.warmwinter.module.user.ui.CommonLoginTelActivity.FORGET_PWD_TEL;
import static com.star.warmwinter.module.user.ui.CommonLoginTelActivity.LOGIN_TYPE_KEY;

/**
 * Author: blackbai11
 * Date: 2018/5/31
 * Description: 登录页面控制器({@link CommonLoginTelActivity})
 */
public class LoginCtrl extends CommonLoginCtrl implements View.OnClickListener {

    public LoginCtrl(Context context) {
        super(context);
    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {
            case R.id.tv_tel_country:
                Toast.makeText(mContext, "国家", Toast.LENGTH_SHORT).show();
                break;

            case R.id.img_next:
                if (TextUtils.isEmpty(commonLoginVM.getPhone())) {
                    ThemeToast.showShort("手机号不能为空");
                    return;
                }
                if (!RegexUtils.isMobileExact(commonLoginVM.getPhone())) {
                    ThemeToast.showShort("请输入正确的手机号");
                    return;
                }
                //网络请求-检测手机是否注册

                //如果未注册-提示手机号未注册

                //如果注册-跳转输入密码界面
                intent = new Intent(mContext, CommonLoginPwdActivity.class);
                intent.putExtra(LOGIN_TYPE_KEY, CommonLoginTelActivity.LOGIN_TYPE_LOGIN);
                intent.putExtra(FORGET_PWD_TEL, commonLoginVM.getPhone());
                mContext.startActivity(intent);
                break;

            case R.id.tv_forget_pwd:
                intent = new Intent(mContext, CommonLoginTelActivity.class);
                intent.putExtra(LOGIN_TYPE_KEY, CommonLoginTelActivity.LOGIN_TYPE_FORGET_PWD);
                intent.putExtra(FORGET_PWD_TEL, commonLoginVM.getPhone());
                mContext.startActivity(intent);
                break;

            case R.id.btn_login:
                if (TextUtils.isEmpty(commonLoginVM.getPwd())) {
                    ThemeToast.showShort("密码不能为空");
                    return;
                }
                if (6 > commonLoginVM.getPwd().length() || 16 < commonLoginVM.getPwd().length()) {
                    ThemeToast.showShort("密码必须为6到16位");
                    return;
                }
                //网络请求-登录检测密码

                //如果登录失败-提示后台返回（密码错误等等）

                //如果登录成功-跳转主页
                Toast.makeText(mContext, "登录成功-跳转主页", Toast.LENGTH_SHORT).show();
                break;
        }

    }

}
